home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / archiver / zoo21src.zoo / addfname.c < prev    next >
C/C++ Source or Header  |  1991-07-24  |  4KB  |  137 lines

  1. #ifndef LINT
  2. static char sccsid[]="@(#) addfname.c 2.11 88/02/06 20:17:17";
  3. #endif /* LINT */
  4.  
  5. /*
  6. Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
  7. (C) Copyright 1988 Rahul Dhesi -- All rights reserved
  8. */
  9. #include "options.h"
  10.  
  11. /* Adds a filename to global list.  (This global list will eventually
  12. be searched by the inlist() function.)  The second and subsequent
  13. parameters suppplied are stored with the name of the file and 
  14. returned by inlist. */
  15.  
  16. #include "zoo.h"  /* Moves zoo.h from 3rd in list to 1st to satisfy */
  17.           /* GCC-ST  -- bjsjr */
  18. #include "zooio.h"
  19. #include "various.h"
  20. #include "zoofns.h"
  21. #include "zoomem.h" /* to get LIST_SIZE */
  22.  
  23. #define FENTRY_BSIZE        80        /* allocation granularity for fentry below */
  24. static struct item **fentry;    /* array of ptrs to file information structs */
  25. static unsigned sz_fentry;        /* its current size */
  26. static int lastname = 0;                  /* index of last name */
  27.  
  28. struct item {              /* global filename list entry */
  29.    char *fname;
  30.    long position;
  31.    unsigned int date;
  32.    unsigned int time;
  33.     unsigned vflag;
  34.     unsigned version_no;
  35. };
  36.  
  37. void addfname(fname, position, date, time, vflag, version_no)
  38. char *fname;
  39. long position;
  40. unsigned int date, time;
  41. unsigned vflag;
  42. unsigned version_no;
  43. {
  44.    if (lastname == 0) {
  45.         sz_fentry = FENTRY_BSIZE;
  46.         fentry = (struct item **) ealloc(sizeof(struct item *) * sz_fentry);
  47.       fentry[0] = (struct item *) ealloc (sizeof(struct item));
  48.     }
  49.  
  50.     /* allocated more memory if needed */
  51.    if (lastname >= sz_fentry - 3) {
  52.         sz_fentry += FENTRY_BSIZE;
  53.         fentry = (struct item **) 
  54.             erealloc(fentry, sizeof(struct item *) * sz_fentry);
  55.     }
  56.  
  57.    fentry[lastname]->fname = str_dup(fname);
  58.    fentry[lastname]->position = position;
  59.    fentry[lastname]->date = date;
  60.    fentry[lastname]->time = time;
  61.     fentry[lastname]->vflag = vflag;
  62.     fentry[lastname]->version_no = version_no;
  63.    lastname++;
  64.    /* allocate memory for empty entry at end */
  65.    fentry[lastname] = (struct item *) ealloc (sizeof(struct item)); 
  66. } /* addfname */
  67.  
  68. /* inlist() */
  69. /* Examines global list built by addfname() to see if supplied filename
  70. is in the list.  
  71.  
  72. If found, returns the file's position within the archive as the function 
  73. value and the date, time, version flag, and version number as parameters.
  74. If not found, returns -1.  Also returns the highest version no. seen
  75. for this filename and the vflag associated with that version.
  76.  
  77. A simple sequential search is done.
  78.  
  79. If justname is nonzero, then the search is for the filename only
  80. without the directory prefix;  else it is for the full
  81. pathname.
  82. */
  83.  
  84. long inlist (fname, date, time, this_version_no, high_vflag, 
  85.                     high_version_no, high_pos, justname)
  86. char *fname;
  87. unsigned int *date, *time;
  88. unsigned *high_vflag;
  89. unsigned *this_version_no;
  90. unsigned *high_version_no;
  91. long *high_pos;
  92. int justname;
  93. {
  94.    register int i = 0;
  95.  
  96.     *high_version_no = 0;
  97.     if (justname)
  98.         fname = nameptr (fname);                    /* if directory wanted */
  99.    fentry[lastname]->fname = fname;          /* sentinel */
  100.     fentry[lastname]->version_no = 0;
  101.  
  102. #ifdef IGNORECASE
  103. #define    COMPARE    str_icmp
  104. #else
  105. #define    COMPARE    strcmp
  106. #endif
  107.  
  108.    while (COMPARE(fname,
  109.             (justname ? nameptr (fentry[i]->fname) : fentry[i]->fname)) != 0) {
  110.       i++;
  111.    }
  112.  
  113.    if (i == lastname)
  114.       return (-1L);
  115.    else {
  116.         int j;
  117.         *date = fentry[i]->date;
  118.         *time = fentry[i]->time;
  119.         *high_pos = fentry[i]->position;
  120.         *high_vflag = fentry[i]->vflag;
  121.         for (j = i; j < lastname; j++) {    /* find highest version no. for file */
  122.             if (COMPARE(fname,
  123.                 (justname ? nameptr (fentry[j]->fname) : fentry[j]->fname)) == 0) {
  124.                 if (*high_version_no < fentry[j]->version_no) {
  125.                     *high_version_no = fentry[j]->version_no;
  126.                     *high_vflag = fentry[j]->vflag;
  127.                     *high_pos = fentry[j]->position;
  128.                     *date = fentry[j]->date;
  129.                     *time = fentry[j]->time;
  130.                 }
  131.             }
  132.         }
  133.         *this_version_no = fentry[i]->version_no;
  134.       return (fentry[i]->position);
  135.    }
  136. } /* inlist() */
  137.